/**
 * @param {number[][]} grid
 * @return {number}
 */
 var projectionArea = function(grid) {
  const n = grid.length;
  let xy = 0;
  const yz = new Array(n).fill(0);
  const xz = new Array(n).fill(0); 
  for(let i = 0; i < n; i++) {
      for(let j = 0; j < n; j++) {
          grid[i][j] && xy++;
          yz[i] = Math.max(yz[i], grid[i][j]);
          xz[i] = Math.max(xz[i], grid[j][i]);
      }
  }
  return xy + yz.reduce((a, b) => a + b) + xz.reduce((a, b) => a + b);
};